<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<!-- /fasttmp/mkdist-qt-4.3.5-1211793125/qtopia-core-opensource-src-4.3.5/src/gui/graphicsview/qgraphicsitem.cpp -->
<head>
  <title>Qt 4.3: QGraphicsTextItem Class Reference</title>
  <link href="classic.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td align="left" valign="top" width="32"><a href="http://www.trolltech.com/products/qt"><img src="images/qt-logo.png" align="left" width="32" height="32" border="0" /></a></td>
<td width="1">&nbsp;&nbsp;</td><td class="postheader" valign="center"><a href="index.html"><font color="#004faf">Home</font></a>&nbsp;&middot; <a href="classes.html"><font color="#004faf">All&nbsp;Classes</font></a>&nbsp;&middot; <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a>&nbsp;&middot; <a href="groups.html"><font color="#004faf">Grouped&nbsp;Classes</font></a>&nbsp;&middot; <a href="modules.html"><font color="#004faf">Modules</font></a>&nbsp;&middot; <a href="functions.html"><font color="#004faf">Functions</font></a></td>
<td align="right" valign="top" width="230"><a href="http://www.trolltech.com"><img src="images/trolltech-logo.png" align="right" width="203" height="32" border="0" /></a></td></tr></table><h1 align="center">QGraphicsTextItem Class Reference<br /><sup><sup>[<a href="qtgui.html">QtGui</a> module]</sup></sup></h1>
<p>The QGraphicsTextItem class provides a text item that you can add to a <a href="qgraphicsscene.html">QGraphicsScene</a> to display formatted text. <a href="#details">More...</a></p>
<pre> #include &lt;QGraphicsTextItem&gt;</pre><p>Inherits <a href="qobject.html">QObject</a> and <a href="qgraphicsitem.html">QGraphicsItem</a>.</p>
<p>This class was introduced in Qt 4.2.</p>
<ul>
<li><a href="qgraphicstextitem-members.html">List of all members, including inherited members</a></li>
</ul>
<a name="properties"></a>
<h3>Properties</h3>
<ul>
<li><div class="fn"/><b><a href="qgraphicstextitem.html#openExternalLinks-prop">openExternalLinks</a></b> : bool</li>
<li><div class="fn"/><b><a href="qgraphicstextitem.html#textCursor-prop">textCursor</a></b> : QTextCursor</li>
</ul>
<ul>
<li><div class="fn"/>1 property inherited from <a href="qobject.html#properties">QObject</a></li>
</ul>
<a name="public-functions"></a>
<h3>Public Functions</h3>
<ul>
<li><div class="fn"/><b><a href="qgraphicstextitem.html#QGraphicsTextItem">QGraphicsTextItem</a></b> ( QGraphicsItem * <i>parent</i> = 0 )</li>
<li><div class="fn"/><b><a href="qgraphicstextitem.html#QGraphicsTextItem-2">QGraphicsTextItem</a></b> ( const QString &amp; <i>text</i>, QGraphicsItem * <i>parent</i> = 0 )</li>
<li><div class="fn"/><b><a href="qgraphicstextitem.html#dtor.QGraphicsTextItem">~QGraphicsTextItem</a></b> ()</li>
<li><div class="fn"/>void <b><a href="qgraphicstextitem.html#adjustSize">adjustSize</a></b> ()</li>
<li><div class="fn"/>QColor <b><a href="qgraphicstextitem.html#defaultTextColor">defaultTextColor</a></b> () const</li>
<li><div class="fn"/>QTextDocument * <b><a href="qgraphicstextitem.html#document">document</a></b> () const</li>
<li><div class="fn"/>QFont <b><a href="qgraphicstextitem.html#font">font</a></b> () const</li>
<li><div class="fn"/>bool <b><a href="qgraphicstextitem.html#openExternalLinks-prop">openExternalLinks</a></b> () const</li>
<li><div class="fn"/>void <b><a href="qgraphicstextitem.html#setDefaultTextColor">setDefaultTextColor</a></b> ( const QColor &amp; <i>col</i> )</li>
<li><div class="fn"/>void <b><a href="qgraphicstextitem.html#setDocument">setDocument</a></b> ( QTextDocument * <i>document</i> )</li>
<li><div class="fn"/>void <b><a href="qgraphicstextitem.html#setFont">setFont</a></b> ( const QFont &amp; <i>font</i> )</li>
<li><div class="fn"/>void <b><a href="qgraphicstextitem.html#setHtml">setHtml</a></b> ( const QString &amp; <i>text</i> )</li>
<li><div class="fn"/>void <b><a href="qgraphicstextitem.html#openExternalLinks-prop">setOpenExternalLinks</a></b> ( bool <i>open</i> )</li>
<li><div class="fn"/>void <b><a href="qgraphicstextitem.html#setPlainText">setPlainText</a></b> ( const QString &amp; <i>text</i> )</li>
<li><div class="fn"/>void <b><a href="qgraphicstextitem.html#textCursor-prop">setTextCursor</a></b> ( const QTextCursor &amp; <i>cursor</i> )</li>
<li><div class="fn"/>void <b><a href="qgraphicstextitem.html#setTextInteractionFlags">setTextInteractionFlags</a></b> ( Qt::TextInteractionFlags <i>flags</i> )</li>
<li><div class="fn"/>void <b><a href="qgraphicstextitem.html#setTextWidth">setTextWidth</a></b> ( qreal <i>width</i> )</li>
<li><div class="fn"/>QTextCursor <b><a href="qgraphicstextitem.html#textCursor-prop">textCursor</a></b> () const</li>
<li><div class="fn"/>Qt::TextInteractionFlags <b><a href="qgraphicstextitem.html#textInteractionFlags">textInteractionFlags</a></b> () const</li>
<li><div class="fn"/>qreal <b><a href="qgraphicstextitem.html#textWidth">textWidth</a></b> () const</li>
<li><div class="fn"/>QString <b><a href="qgraphicstextitem.html#toHtml">toHtml</a></b> () const</li>
<li><div class="fn"/>QString <b><a href="qgraphicstextitem.html#toPlainText">toPlainText</a></b> () const</li>
</ul>
<ul>
<li><div class="fn"/>29 public functions inherited from <a href="qobject.html#public-functions">QObject</a></li>
<li><div class="fn"/>114 public functions inherited from <a href="qgraphicsitem.html#public-functions">QGraphicsItem</a></li>
</ul>
<a name="signals"></a>
<h3>Signals</h3>
<ul>
<li><div class="fn"/>void <b><a href="qgraphicstextitem.html#linkActivated">linkActivated</a></b> ( const QString &amp; <i>link</i> )</li>
<li><div class="fn"/>void <b><a href="qgraphicstextitem.html#linkHovered">linkHovered</a></b> ( const QString &amp; <i>link</i> )</li>
</ul>
<ul>
<li><div class="fn"/>1 signal inherited from <a href="qobject.html#signals">QObject</a></li>
</ul>
<h3>Additional Inherited Members</h3>
<ul>
<li><div class="fn"/>1 public slot inherited from <a href="qobject.html#public-slots">QObject</a></li>
<li><div class="fn"/>5 static public members inherited from <a href="qobject.html#static-public-members">QObject</a></li>
<li><div class="fn"/>1 static public member inherited from <a href="qgraphicsitem.html#static-public-members">QGraphicsItem</a></li>
<li><div class="fn"/>7 protected functions inherited from <a href="qobject.html#protected-functions">QObject</a></li>
<li><div class="fn"/>23 protected functions inherited from <a href="qgraphicsitem.html#protected-functions">QGraphicsItem</a></li>
</ul>
<a name="details"></a>
<hr />
<h2>Detailed Description</h2>
<p>The QGraphicsTextItem class provides a text item that you can add to a <a href="qgraphicsscene.html">QGraphicsScene</a> to display formatted text.</p>
<p>To set the item's text, pass a <a href="qstring.html">QString</a> to QGraphicsTextItem's constructor, or call <a href="qgraphicstextitem.html#setHtml">setHtml</a>()/<a href="qgraphicstextitem.html#setPlainText">setPlainText</a>().</p>
<p>QGraphicsTextItem uses the text's formatted size and the associated font to provide a reasonable implementation of <a href="qgraphicsitem.html#boundingRect">boundingRect</a>(), <a href="qgraphicsitem.html#shape">shape</a>(), and <a href="qgraphicsitem.html#contains">contains</a>(). You can set the font by calling <a href="qgraphicstextitem.html#setFont">setFont</a>().</p>
<p>It is possible to make the item editable by setting the <a href="qt.html#TextInteractionFlag-enum">Qt::TextEditable</a> flag using <a href="qgraphicstextitem.html#setTextInteractionFlags">setTextInteractionFlags</a>().</p>
<p>The item's preferred text width can be set using <a href="qgraphicstextitem.html#setTextWidth">setTextWidth</a>() and obtained using <a href="qgraphicstextitem.html#textWidth">textWidth</a>().</p>
<p><b>Note:</b> In order to align HTML text in the center, the item's text width must be set.</p>
<p align="center"><img src="images/graphicsview-textitem.png" /></p><p>See also <a href="qgraphicssimpletextitem.html">QGraphicsSimpleTextItem</a>, <a href="qgraphicspathitem.html">QGraphicsPathItem</a>, <a href="qgraphicsrectitem.html">QGraphicsRectItem</a>, <a href="qgraphicsellipseitem.html">QGraphicsEllipseItem</a>, <a href="qgraphicspixmapitem.html">QGraphicsPixmapItem</a>, <a href="qgraphicspolygonitem.html">QGraphicsPolygonItem</a>, <a href="qgraphicslineitem.html">QGraphicsLineItem</a>, and <a href="graphicsview.html">The Graphics View Framework</a>.</p>
<hr />
<h2>Property Documentation</h2>
<h3 class="fn"><a name="openExternalLinks-prop"></a>openExternalLinks : bool</h3>
<p>Specifies whether <a href="qgraphicstextitem.html">QGraphicsTextItem</a> should automatically open links using <a href="qdesktopservices.html#openUrl">QDesktopServices::openUrl</a>() instead of emitting the anchorClicked signal.</p>
<p>The default value is false.</p>
<p>Access functions:</p>
<ul>
<li><div class="fn"/><b>bool openExternalLinks () const</b></li>
<li><div class="fn"/><b>void setOpenExternalLinks ( bool <i>open</i> )</b></li>
</ul>
<h3 class="fn"><a name="textCursor-prop"></a>textCursor : <a href="qtextcursor.html">QTextCursor</a></h3>
<p>This property represents the visible text cursor in an editable text item.</p>
<p>Access functions:</p>
<ul>
<li><div class="fn"/><b>QTextCursor textCursor () const</b></li>
<li><div class="fn"/><b>void setTextCursor ( const QTextCursor &amp; <i>cursor</i> )</b></li>
</ul>
<hr />
<h2>Member Function Documentation</h2>
<h3 class="fn"><a name="QGraphicsTextItem"></a>QGraphicsTextItem::QGraphicsTextItem ( <a href="qgraphicsitem.html">QGraphicsItem</a> * <i>parent</i> = 0 )</h3>
<p>Constructs a <a href="qgraphicstextitem.html">QGraphicsTextItem</a>. <i>parent</i> is passed to <a href="qgraphicsitem.html">QGraphicsItem</a>'s constructor.</p>
<p>See also <a href="qgraphicsscene.html#addItem">QGraphicsScene::addItem</a>().</p>
<h3 class="fn"><a name="QGraphicsTextItem-2"></a>QGraphicsTextItem::QGraphicsTextItem ( const <a href="qstring.html">QString</a> &amp; <i>text</i>, <a href="qgraphicsitem.html">QGraphicsItem</a> * <i>parent</i> = 0 )</h3>
<p>Constructs a <a href="qgraphicstextitem.html">QGraphicsTextItem</a>, using <i>text</i> as the default plain text. <i>parent</i> is passed to <a href="qgraphicsitem.html">QGraphicsItem</a>'s constructor.</p>
<p>See also <a href="qgraphicsscene.html#addItem">QGraphicsScene::addItem</a>().</p>
<h3 class="fn"><a name="dtor.QGraphicsTextItem"></a>QGraphicsTextItem::~QGraphicsTextItem ()</h3>
<p>Destroys the <a href="qgraphicstextitem.html">QGraphicsTextItem</a>.</p>
<h3 class="fn"><a name="adjustSize"></a>void QGraphicsTextItem::adjustSize ()</h3>
<p>Adjusts the text item to a reasonable size.</p>
<h3 class="fn"><a name="defaultTextColor"></a><a href="qcolor.html">QColor</a> QGraphicsTextItem::defaultTextColor () const</h3>
<p>Returns the default text color that is used to for unformatted text.</p>
<p>See also <a href="qgraphicstextitem.html#setDefaultTextColor">setDefaultTextColor</a>().</p>
<h3 class="fn"><a name="document"></a><a href="qtextdocument.html">QTextDocument</a> * QGraphicsTextItem::document () const</h3>
<p>Returns the item's text document.</p>
<p>See also <a href="qgraphicstextitem.html#setDocument">setDocument</a>().</p>
<h3 class="fn"><a name="font"></a><a href="qfont.html">QFont</a> QGraphicsTextItem::font () const</h3>
<p>Returns the item's font, which is used to render the text.</p>
<p>See also <a href="qgraphicstextitem.html#setFont">setFont</a>().</p>
<h3 class="fn"><a name="linkActivated"></a>void QGraphicsTextItem::linkActivated ( const <a href="qstring.html">QString</a> &amp; <i>link</i> )&nbsp;&nbsp;<tt> [signal]</tt></h3>
<p>This signal is emitted when the user clicks on a link on a text item that enables <a href="qt.html#TextInteractionFlag-enum">Qt::LinksAccessibleByMouse</a> or <a href="qt.html#TextInteractionFlag-enum">Qt::LinksAccessibleByKeyboard</a>. <i>link</i> is the link that was clicked.</p>
<p>See also <a href="qgraphicstextitem.html#setTextInteractionFlags">setTextInteractionFlags</a>().</p>
<h3 class="fn"><a name="linkHovered"></a>void QGraphicsTextItem::linkHovered ( const <a href="qstring.html">QString</a> &amp; <i>link</i> )&nbsp;&nbsp;<tt> [signal]</tt></h3>
<p>This signal is emitted when the user hovers over a link on a text item that enables <a href="qt.html#TextInteractionFlag-enum">Qt::LinksAccessibleByMouse</a>. <i>link</i> is the link that was hovered over.</p>
<p>See also <a href="qgraphicstextitem.html#setTextInteractionFlags">setTextInteractionFlags</a>().</p>
<h3 class="fn"><a name="setDefaultTextColor"></a>void QGraphicsTextItem::setDefaultTextColor ( const <a href="qcolor.html">QColor</a> &amp; <i>col</i> )</h3>
<p>Sets the color for unformatted text to <i>col</i>.</p>
<p>See also <a href="qgraphicstextitem.html#defaultTextColor">defaultTextColor</a>().</p>
<h3 class="fn"><a name="setDocument"></a>void QGraphicsTextItem::setDocument ( <a href="qtextdocument.html">QTextDocument</a> * <i>document</i> )</h3>
<p>Sets the text document <i>document</i> on the item.</p>
<p>See also <a href="qgraphicstextitem.html#document">document</a>().</p>
<h3 class="fn"><a name="setFont"></a>void QGraphicsTextItem::setFont ( const <a href="qfont.html">QFont</a> &amp; <i>font</i> )</h3>
<p>Sets the font used to render the text item to <i>font</i>.</p>
<p>See also <a href="qgraphicstextitem.html#font">font</a>().</p>
<h3 class="fn"><a name="setHtml"></a>void QGraphicsTextItem::setHtml ( const <a href="qstring.html">QString</a> &amp; <i>text</i> )</h3>
<p>Sets the item's text to <i>text</i>, assuming that text is HTML formatted. If the item has keyboard input focus, this function will also call <a href="qgraphicsitem.html#ensureVisible">ensureVisible</a>() to ensure that the text is visible in all viewports.</p>
<p>See also <a href="qgraphicstextitem.html#toHtml">toHtml</a>() and <a href="qgraphicsitem.html#hasFocus">hasFocus</a>().</p>
<h3 class="fn"><a name="setPlainText"></a>void QGraphicsTextItem::setPlainText ( const <a href="qstring.html">QString</a> &amp; <i>text</i> )</h3>
<p>Sets the item's text to <i>text</i>. If the item has keyboard input focus, this function will also call <a href="qgraphicsitem.html#ensureVisible">ensureVisible</a>() to ensure that the text is visible in all viewports.</p>
<p>See also <a href="qgraphicstextitem.html#toHtml">toHtml</a>() and <a href="qgraphicsitem.html#hasFocus">hasFocus</a>().</p>
<h3 class="fn"><a name="setTextInteractionFlags"></a>void QGraphicsTextItem::setTextInteractionFlags ( <a href="qt.html#TextInteractionFlag-enum">Qt::TextInteractionFlags</a> <i>flags</i> )</h3>
<p>Sets the flags <i>flags</i> to specify how the text item should react to user input.</p>
<p>The default for a <a href="qgraphicstextitem.html">QGraphicsTextItem</a> is <a href="qt.html#TextInteractionFlag-enum">Qt::NoTextInteraction</a>. Setting a value different to <a href="qt.html#TextInteractionFlag-enum">Qt::NoTextInteraction</a> will also set the <a href="qgraphicsitem.html#GraphicsItemFlag-enum">ItemIsFocusable</a> <a href="qgraphicsitem.html">QGraphicsItem</a> flag.</p>
<p>By default, the text is read-only. To transform the item into an editor, set the <a href="qt.html#TextInteractionFlag-enum">Qt::TextEditable</a> flag.</p>
<p>See also <a href="qgraphicstextitem.html#textInteractionFlags">textInteractionFlags</a>().</p>
<h3 class="fn"><a name="setTextWidth"></a>void QGraphicsTextItem::setTextWidth ( <a href="qtglobal.html#qreal-typedef">qreal</a> <i>width</i> )</h3>
<p>Sets the preferred width for the item's text. If the actual text is wider than the specified width then it will be broken into multiple lines.</p>
<p>If <i>width</i> is set to -1 then the text will not be broken into multiple lines unless it is enforced through an explicit line break or a new paragraph.</p>
<p>The default value is -1.</p>
<p>See also <a href="qgraphicstextitem.html#textWidth">textWidth</a>().</p>
<h3 class="fn"><a name="textInteractionFlags"></a><a href="qt.html#TextInteractionFlag-enum">Qt::TextInteractionFlags</a> QGraphicsTextItem::textInteractionFlags () const</h3>
<p>Returns the current text interaction flags.</p>
<p>See also <a href="qgraphicstextitem.html#setTextInteractionFlags">setTextInteractionFlags</a>().</p>
<h3 class="fn"><a name="textWidth"></a><a href="qtglobal.html#qreal-typedef">qreal</a> QGraphicsTextItem::textWidth () const</h3>
<p>Returns the text width.</p>
<p>See also <a href="qgraphicstextitem.html#setTextWidth">setTextWidth</a>().</p>
<h3 class="fn"><a name="toHtml"></a><a href="qstring.html">QString</a> QGraphicsTextItem::toHtml () const</h3>
<p>Returns the item's text converted to HTML, or an empty <a href="qstring.html">QString</a> if no text has been set.</p>
<p>See also <a href="qgraphicstextitem.html#setHtml">setHtml</a>().</p>
<h3 class="fn"><a name="toPlainText"></a><a href="qstring.html">QString</a> QGraphicsTextItem::toPlainText () const</h3>
<p>Returns the item's text converted to plain text, or an empty <a href="qstring.html">QString</a> if no text has been set.</p>
<p>See also <a href="qgraphicstextitem.html#setPlainText">setPlainText</a>().</p>
<p /><address><hr /><div align="center">
<table width="100%" cellspacing="0" border="0"><tr class="address">
<td width="30%">Copyright &copy; 2008 <a href="trolltech.html">Trolltech</a></td>
<td width="40%" align="center"><a href="trademarks.html">Trademarks</a></td>
<td width="30%" align="right"><div align="right">Qt 4.3.5</div></td>
</tr></table></div></address></body>
</html>
